<%--
  Created by IntelliJ IDEA.
  User: 亮亮
  Date: 2017/9/27
  Time: 9:25
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<html>
<head>
<base href="<%=basePath%>">

<meta charset="UTF-8">
<title>Mua~亲亲宠——宠物交易领养信息平台</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap theme -->
<link href="css/bootstrap-theme.min.css" rel="stylesheet">
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
	<%@ include file="/WEB-INF/jsp/top.jspf"%>
	<%@ include file="/WEB-INF/jsp/search.jspf"%>

	<div>
		<div class="col-sm-offset-1 col-sm-10">
			<div style="height: 30px">
				<span class="label label-info">最新上架</span> <a href="pet/searchPet.do"><button
						class="btn btn-link col-sm-offset-9">查看更多...</button> </a>
			</div>
			<div id="newest_pets" class="row"></div>
		</div>
	</div>
	<script type="text/javascript">
		$(document).ready(function() {
			onload();
		});
		function onload() {
			$
					.ajax({
						url : "pet/listNewestPet.do",
						success : function(result) {
							if (result.msg == 'success') {
								var list = result.petList;
								var innerText = "";
								for ( var no in list) {
									if (list[no].icon == null
											|| list[no].icon == "") {
										list[no].icon = "images/pet_icon.jpg";
									}
									if (list[no].price == null
											|| list[no].price<0.009) {
										list[no].price = "免费";
									}
									innerText = innerText
											+ " <div class='col-sm-3'> <div class='thumbnail' style='cursor:pointer' onclick = 'findPet("
											+ list[no].id
											+ ")'><img style='height: 200px;width: 180px' src='"
											+list[no].icon+"' alt='"+list[no].title
											+"'  class='img-responsive' onerror=\"this.src='images/pet_icon.jpg'\"><div class='caption'><h4>￥"
											+ list[no].price + "</h4><p>"
											+ list[no].title
											+ "</p></div></div></div>";
								}
								$("#newest_pets").html(innerText);
							} else {
								$("#newest_pets")
										.html(
												"<button  class='btn btn-info' onclick='onload()'>重新加载</button>");
							}

						}

					});
		}
		function findPet(pet_id) {
			window.open("pet/showPetDetail.do?id=" + pet_id);
		}
	</script>
</body>
</html>